//+--------------------------------------------------------------------
//| Copyright(c) 2012 - an.vuongngocduy					
//| This file is a part of Compact Game Engine (CGE)	
//+--------------------------------------------------------------------
#ifndef __CGE_IMAGE_H__
#define __CGE_IMAGE_H__

#include "cgeCommons.h"
#include "cgeAllocator.h"
#include "cgeProperty.h"
#include "cgeEnums.h"
#include "cgeColor.h"
#include "cgeSize2.h"

using namespace cge::std;

namespace cge
{
	namespace gfx
	{
		class Image
		{
		public:
			/// Default constructor
			Image();

			/// Copy constructor
			Image(const Image& img);

			/// Construct new image form specified format and size
			Image(EPixelFormat format, const Size2u& size);

			/// Construct new image from buffer that have specified format and size
			Image(const u8* data, EPixelFormat format, const Size2u& size);
	
			/// Construct new image from buffer or use external memory directly
			Image(u8* data, EPixelFormat format,  const Size2u& dimension, b8 useExternalMem);

			/// Destructor
			~Image();

			/// Return pixel format
			EPixelFormat PixelFormat() const;

			/// Return size of image in byte
			u32 Size() const;
			
			/// Return bits per pixel
			u32 BitsPerPixel() const;
			
			/// Return image's width 
			u32 Width() const;
			
			/// Return image's height
			u32 Height() const;

			/// Return pointer to image's data
			const u8* Data() const;

			/// Return pointer to image's data
			u8* Data();			

			/// Get color of pixel at specified position
			Color GetPixel(u32 x, u32 y) const;

			/// Set color of pixel at specified position
			Image& SetPixel(const Color& col, u32 x, u32 y);
			
			/// Flip the image around X-axis
			Image& FlipVertical();

			/// Flip image around Y-axis
			Image& FlipHorizontal();

			/// Release resources used by image
			void Dispose();

			/// Copy content of specified image into current image
			Image& operator = (const Image& img);

		protected:
			u8* mData;
			Size2u mDimension;
			EPixelFormat mFormat;
			Allocator<u8> mAlloc;
		};
	}
}

#endif//__CGE_IMAGE_H__